﻿using ConfExpert.Forms.Base;
using DevTeam;
using System;

namespace ConfExpert.Forms.Siparisler
{
    public partial class IstenenGelenAnalizi : XForm
    {
        public IstenenGelenAnalizi()
        {
            InitializeComponent();
        }

        private void IstenenGelenAnalizi_Load(object sender, EventArgs e)
        {
            cmbGrouping.EditValue = "Müşteri";
            gridView1.Init("GetGelenIstenenAnaliz", cmbGrouping.EditValue.ToStr(), 0);
            gridView1.AddDetailGrid(gridView2, cmbGrouping.EditValue.ToStr() == "Üretici" ? "VendorId" : "CustomerId");

            cmbGrouping.EditValueChanged += cmbGrouping_EditValueChanged;
            cmbYıl.EditValueChanged += cmbYıl_EditValueChanged;
            gridView1.FocusedRowChanged += gridView1_FocusedRowChanged;
            cmbYıl.EditValue = 2015;
        }

        void cmbGrouping_EditValueChanged(object sender, EventArgs e)
        {
            Rfrsh();
        }

        void gridView1_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            gridView2.BestFitColumns();
        }

        void cmbYıl_EditValueChanged(object sender, EventArgs e)
        {
            Rfrsh();
        }

        private void Rfrsh()
        {
            gridView1.Init("GetGelenIstenenAnaliz", cmbGrouping.EditValue.ToStr(), cmbYıl.EditValue.ToInt());
            gridView1.AddDetailGrid(gridView2, cmbGrouping.EditValue.ToStr() == "Üretici" ? "VendorId" : "CustomerId");

            gridView1.FormatAsNumber(1, "GelenQty", "IstenenQty");
            gridView2.FormatAsNumber(1, "GelenQty", "IstenenQty");

            gridView1.SetCaptions("FazlaGelis:Fazla Geliş %");
            gridView1.FormatAsPercentage(1, "FazlaGelis");
            gridView1.AddSummary("GelenQty", "IstenenQty");

            gridView2.SetCaptions("FazlaGelis:Fazla Geliş %");
            gridView2.FormatAsPercentage(1, "FazlaGelis");
            gridView2.AddSummary("GelenQty", "IstenenQty");

            gridView1.BestFitColumns();
            gridView2.BestFitColumns();
        }
    }
}
